<?php
/*
    注：以下代码只实现了上传，并没有细致验证，只测试使用
 */
foreach ($_FILES as $key => $file) {
    if ($file['error'] > 0) {
        returnAjax(1,$file['error']);
    }
    if (empty($file['name'])){
        returnAjax(1,'未知上传错误！');
    }
    if (!is_uploaded_file($file['tmp_name'])) {
        returnAjax(1,'非法上传文件！');
    }
    if($file['size'] > 1024*1024) {
        returnAjax(1,'上传文件太大');
    }
    $file['name']  = strip_tags($file['name']);
    $file['ext']   = pathinfo($file['name'], PATHINFO_EXTENSION);
    $ext = strtolower($file['ext']);
    if(in_array($ext, array('gif','jpg','jpeg','bmp','png'))) {
        $imginfo = getimagesize($file['tmp_name']);
        if(empty($imginfo) || ($ext == 'gif' && empty($imginfo['bits']))){
            returnAjax(1,'非法图像文件！');
        }
    } else {
        returnAjax(1,'上传文件类型不允许');
    }
    if(!is_dir('uploads/')) {
        mkdir('uploads/');
    }
    $uploads = time().rand(1,10000).'.'.$ext;
    move_uploaded_file( $file['tmp_name'], 'uploads/' . $uploads );
    returnAjax(0, $uploads);
}

function returnAjax($status,$msg) {
    echo json_encode(array('error'=>$status, 'info' => $msg));
    exit;
}



